<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <% String contextPath = request.getContextPath(); %>
    <%@ page import="java.util.*" %>
    <%@ page import="common.*" %>
<%
	 Cart cart= (Cart)session.getAttribute("opecart");
		Customer cs= (Customer)session.getAttribute("customer");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<link href="<%= contextPath %>/css/order.css" rel="stylesheet" type="text/css">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>確認（帳票）</title>
	</head>
	<body>
	<!-- <div id="order"> -->
	<div id="">
			<div><p> 注文者： <%=cs.getName() %> 様 </p></div>
		<form action="<%= request.getContextPath() %>/orderOpe/JudgeServlet">
			<div>
			<table>
				<tr>
					<td>商品コード</td>
					<td>商品名</td>
					<td>規格</td>
					<td>単価</td>
					<td>注文数</td>
					<td>在庫数</td>
					<td>合計金額</td>
				</tr>
				
				<%int total=0 ;%>
				<% List<OrderItem> items = cart.getItems(); %>
				<%for(int i=0; i<=10; i++){ %>
					<%	if(i <items.size()) { %>
						<%OrderItem item= items.get(i); %>
						<% String code = item.getItem_code(); %>
						<% Item It = Item.find_by_code(code); %>
					<tr>
						<td width="105">
							<%=code %>
							<input type="hidden" name="code" value="<%=cart.getCode() %>">
						</td>
						<td width="400">
							<%= It.getName() %>
						</td>
						<td>
							<%= It.getSize() %>
						</td>						
						<td>
							<%= It.getPrice() %>
						</td>					
						<td>
							<%=item.getOrders() %>
						</td>
						<td>
							<%= It.getStock() %>
						</td>
						<td width="100">
							<%= It.getPrice() * item.getOrders() %>
							
							<input type="hidden"name="cost_total"value="<%= It.getCost() * item.getOrders() %>">
						</td>
					</tr>
					<% total = total + It.getPrice() * item.getOrders(); %>
					<% } else { %>
					<tr>
						<td height="20">
						</td>
						<td width="350">
						</td>
						<td>
						</td>
						<td>
						</td>
						<td>
						</td>					
						<td>
						</td>
						<td>
						</td>
					</tr>
					<% } %>
				<% } %>
				
				<tr>
					<td frame="void"></td>
					<td frame="void"></td>
					<td colspan="3">合計</td>
					<td colspan="2"><%=total%><input type="hidden" name="total" value="<%=total%>" />円</td>
				</tr>
				<tr>
					<td frame="void"></td>
					<td frame="void"></td>
					<td colspan="3">配送料</td>

					<td colspan="2">
						<% int deliver = (total >= 10000) ? 0 : 500; %><%= deliver %>
						<input type="hidden" name="deliver" value="<%= deliver %>" />円</td>
				</tr>
				<tr>
					<td frame="void"></td>
					<td frame="void"></td>
					<td colspan="3">合計請求金額</td>
					<td colspan="2">
						<%= total + deliver %>
						<input type="hidden" name="all" value="<%= total + deliver %>" />円</td>
				</tr>
			</table>
			</div>
			
		配達希望日<select name="hope" size="1">
			<option value="1">指定なし
			<option value="2">2日後
			<option value="3">3日後
			<option value="4">4日後
			<option value="5">5日後
			<option value="6">6日後
			<option value="7">7日後
		</select>
		<br>
		<input type="submit" value="注文確定">
		</form>
		<br>
		<form action="order_Input.jsp">
			<% List<OrderItem> itemlist = cart.getItems(); %>
			<% for(int i=0; i<10; i++){ %>
				<% if(i < itemlist.size()) { %>
					<% OrderItem item = itemlist.get(i); %>
					<input type="hidden" name="code" value="<%= item.getItem_code() %>" />
					<input type="hidden" name="orders" value="<%= item.getOrders() %>" />
				<% } else { %>
					<input type="hidden" name="code" value="" />
					<input type="hidden" name="orders" value="" />
				<% } %>
			<% } %>
		<input type="submit"value="戻る">
		</form>
		</div>
	</body>
</html>
